package vista;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.KeyListener;

import javax.swing.BorderFactory;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JEditorPane;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTable;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.border.BevelBorder;
import javax.swing.border.LineBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.SwingUtilities;
import java.util.*;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class FormProducto extends javax.swing.JFrame {
	
	private JPanel jPanel1;
	private JLabel jLabel3, jLabel4,  jLabel5;
	private JLabel jLabel7;
	private JSeparator jSeparator4;
	private JLabel jLabel6;
	private JPanel Fondo4;
	private JSeparator jSeparator3;
	private JSeparator jSeparator2;
	private JButton bntBuscar, bntIncluir, bntGuardar, bntEliminar, bntCancelar, bntSalir;
	private JScrollPane TablaIngredientes;
	private JTable TablaIngredienteProd;
	private JSeparator jSeparator6;
	private JSeparator jSeparator5;
	private JTextField txtcantidad;
	private JLabel jLabel8;
	private JSeparator jSeparator1;
	private JComboBox comboCategoria, comboIng;
	private JTextField txtpreciou;
	private JTextField txtdescripcion;
	private JTextField txtcodprod;
	private JPanel jPanel3;
	private JLabel jLabel2;
	private JLabel jLabel1;
	private JPanel jPanel2;
	int t = 0;
	boolean bool = false;
	private Object VAL[][];
    
	/*Metodos para Llenar la Tabla de Ingredientes*/
	public Object [][] GetDatos()
	{
		return VAL;
	}
	public void VaciarDatos()
	{
		VAL = new Object[0][0];
		t = 0;
		bool = false;
	}

	public void Anadir(List<Object>L)
	{
		
		Object[][]aux  = new Object[++t][2];
		for(int i = 0;i < t-1;i++)
			for(int j = 0;j < 2;j++)
				aux[i][j] = VAL[i][j];

		
		for(int i = 0;i < 2;i++)
			aux[t-1][i] = L.get(i);
		
		
		VAL  = new Object[t][2];
		for(int i = 0;i < t;i++)
			for(int j = 0;j < 2;j++)
				VAL[i][j] = aux[i][j];
		t = bool == true ? t : 0;
		bool = true;
		CargarTabla();
	}
	
	public void CargarTabla()
	{
		TableModel jTable1Model = 
		new DefaultTableModel
		(VAL,new String[] {"Ingrediente"," Cantidad "});
		
		TablaIngredienteProd = new JTable();
		TablaIngredientes.setViewportView(TablaIngredienteProd);
		TablaIngredienteProd.setModel(jTable1Model);
		TablaIngredienteProd.setBounds(71, 308, 457, 35);
		TablaIngredienteProd.setShowVerticalLines(false);
		TablaIngredienteProd.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
		TablaIngredienteProd.setToolTipText("");
		TablaIngredienteProd.setOpaque(false);
		TablaIngredienteProd.setPreferredSize(new java.awt.Dimension(601, 149));
	}

	public int N_Elementos()
	{
		return t;
	}
	
	public FormProducto() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			getContentPane().setBackground(Color.white);
			this.setName("Formulario Producto");
			this.setTitle("Formulario Producto");
			this.setFont(new java.awt.Font("Courier 10 Pitch",0,28));
			{
				jPanel1 = new JPanel();
				getContentPane().add(jPanel1).setBackground(Color.white);
				jPanel1.setBounds(0, 0, 481, 616);
				getContentPane().add(jPanel1, "Center");
				getContentPane().setBackground(Color.white);
				jPanel1.setLayout(null);
				{
					jPanel2 = new JPanel();
					jPanel1.add(jPanel2);
					jPanel2.setLayout(null);
					jPanel2.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
					getContentPane().setBackground(Color.white);
					jPanel2.setBounds(45, 74, 400, 182);
					{
						jLabel2 = new JLabel();
						jPanel2.add(jLabel2);
						jLabel2.setText("Cod. Producto");
						jLabel2.setBounds(17, 17, 112, 18);
						jLabel2.setFont(new java.awt.Font("Dialog",0,14));
					}
					{
						jLabel3 = new JLabel();
						jPanel2.add(jLabel3);
						jLabel3.setText("Descripcion");
						jLabel3.setBounds(18, 64, 105, 22);
						jLabel3.setFont(new java.awt.Font("Dialog",0,14));
					}
					{
						jLabel4 = new JLabel();
						jPanel2.add(jLabel4);
						jLabel4.setText("Precio Unitario");
						jLabel4.setBounds(18, 108, 110, 20);
						jLabel4.setFont(new java.awt.Font("Dialog",0,14));
					}
					{
						jLabel5 = new JLabel();
						jPanel2.add(jLabel5);
						jLabel5.setText("Categoria");
						jLabel5.setBounds(18, 148, 92, 21);
						jLabel5.setFont(new java.awt.Font("Dialog",0,14));
					}
					{
						txtcodprod = new JTextField();
						jPanel2.add(txtcodprod);
						txtcodprod.setBounds(127, 14, 183, 26);
					}
					{
						txtdescripcion = new JTextField();
						jPanel2.add(txtdescripcion);
						txtdescripcion.setBounds(128, 61, 183, 26);
					}
					{
						txtpreciou = new JTextField();
						jPanel2.add(txtpreciou);
						txtpreciou.setBounds(128, 102, 185, 26);
					}
					{
						comboCategoria = new JComboBox();
						jPanel2.add(comboCategoria);
						comboCategoria.setBounds(128, 145, 185, 26);
						comboCategoria.setFont(new java.awt.Font("Dialog",0,14));
						comboCategoria.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
					}
					{
						bntBuscar = new JButton();
						jPanel2.add(bntBuscar);
						bntBuscar.setText("B");
						bntBuscar.setIcon(new ImageIcon(getClass().getClassLoader().getResource("imagenes/buscar1.png")));
						bntBuscar.setBounds(321, 12, 67, 32);
					}
					{
						jSeparator2 = new JSeparator();
						jPanel2.add(jSeparator2);
						jSeparator2.setBounds(14, 51, 372, 10);
					}
				}
				{
					jPanel3 = new JPanel();
					jPanel1.add(jPanel3);
					jPanel3.setBounds(12, 533, 457, 63);
					jPanel3.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
					jPanel3.setLayout(null);
					{
						bntGuardar = new JButton();
						jPanel3.add(bntGuardar);
						bntGuardar.setText("Guardar");
						bntGuardar.setIcon(new ImageIcon(getClass().getClassLoader().getResource("imagenes/aceptar.png")));
						bntGuardar.setBounds(8, 14, 118, 38);
						bntGuardar.setFont(new java.awt.Font("Dialog",0,11));
					}
					{
						bntEliminar = new JButton();
						jPanel3.add(bntEliminar);
						bntEliminar.setText("Eliminar");
						bntEliminar.setIcon(new ImageIcon(getClass().getClassLoader().getResource("imagenes/eliminar1.png")));
						bntEliminar.setBounds(132, 14, 119, 38);
						bntEliminar.setFont(new java.awt.Font("Dialog",0,11));
					}
					{
						bntCancelar = new JButton();
						jPanel3.add(bntCancelar);
						bntCancelar.setText("Cancelar");
						bntCancelar.setIcon(new ImageIcon(getClass().getClassLoader().getResource("imagenes/eliminar.png")));
						bntCancelar.setBounds(258, 15, 121, 38);
						bntCancelar.setFont(new java.awt.Font("Dialog",0,11));
					}
					{
						bntSalir = new JButton();
						jPanel3.add(bntSalir);
						bntSalir.setText("S");
						bntSalir.setIcon(new ImageIcon(getClass().getClassLoader().getResource("imagenes/salir1.png")));
						bntSalir.setBounds(387, 14, 61, 38);
					}

				}
				{
					jSeparator1 = new JSeparator();
					jPanel1.add(jSeparator1);
					jSeparator1.setBounds(79, 59, 318, 7);
				}
				{
					jSeparator3 = new JSeparator();
					jPanel1.add(jSeparator3);
					jSeparator3.setBounds(81, 22, 318, 9);
				}
				{
					jLabel1 = new JLabel();
					jPanel1.add(jLabel1);
					jLabel1.setText("Datos del Producto");
					jLabel1.setBounds(86, 26, 311, 36);
					jLabel1.setFont(new java.awt.Font("Purisa",1,26));
				}
				{
					Fondo4 = new JPanel();
					jPanel1.add(Fondo4);
					Fondo4.setBounds(23, 284, 437, 237);
					Fondo4.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
					Fondo4.setLayout(null);
					{
						jLabel6 = new JLabel();
						Fondo4.add(jLabel6);
						jLabel6.setText("Asignarle Ingredientes");
						jLabel6.setFont(new java.awt.Font("Purisa",0,20));
						jLabel6.setBounds(83, 11, 259, 35);
					}
					{
						jSeparator4 = new JSeparator();
						Fondo4.add(jSeparator4);
						jSeparator4.setBounds(72, 44, 279, 10);
					}
					{
						jLabel7 = new JLabel();
						Fondo4.add(jLabel7);
						jLabel7.setText("Ingrediente");
						jLabel7.setBounds(10, 59, 83, 23);
						jLabel7.setFont(new java.awt.Font("Dialog",0,14));
					}
					{
						comboIng = new JComboBox();
						Fondo4.add(comboIng);
						comboIng.setBounds(93, 58, 154, 26);
						comboIng.setFont(new java.awt.Font("Dialog",0,14));
					}
					{
						jLabel8 = new JLabel();
						Fondo4.add(jLabel8);
						jLabel8.setText("Cantidad:");
						jLabel8.setBounds(254, 59, 71, 23);
						jLabel8.setFont(new java.awt.Font("Dialog",0,14));
					}
					{
						txtcantidad = new JTextField();
						Fondo4.add(getTxtcantidad());
						txtcantidad.setBounds(322, 59, 49, 26);
					}
					{
						jSeparator6 = new JSeparator();
						Fondo4.add(jSeparator6);
						jSeparator6.setBounds(8, 96, 417, 11);
					}
					{
						bntIncluir = new JButton();
						Fondo4.add(bntIncluir);
						bntIncluir.setText("I");
						bntIncluir.setIcon(new ImageIcon(getClass().getClassLoader().getResource("imagenes/aceptar.png")));
						bntIncluir.setBounds(376, 55, 54, 33);
					}
					{
						TablaIngredientes = new JScrollPane();
						Fondo4.add(TablaIngredientes);
						TablaIngredientes.setBounds(14, 113, 409, 110);
						
					}
				}
				{
					jSeparator5 = new JSeparator();
					jPanel1.add(jSeparator5);
					jSeparator5.setBounds(0, 270, 481, 10);
				}
			}
			pack();
			this.setSize(487, 645);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
	/*public void addKeyListener(KeyListener kl)
	{
		txtcantidad.addKeyListener(kl);
	}*/
	
	public JComboBox GetcomboIngredientes()
	{
	   return comboIng;
    }
	public void SetcomboIngredientes(int i)
	{
		comboIng.setSelectedIndex(i);
    }
	public void SetcomboIngredientes(String str)
	{
		ComboBoxModel modelo = new DefaultComboBoxModel(str.split(","));
		comboIng.setModel(modelo);
    }
	public void Settxtcantidad(int n){
		txtcantidad.setText(""+n);
	}
	public void addListener(ActionListener actionListener) {
		this.bntIncluir.addActionListener(actionListener);
		this.bntBuscar.addActionListener(actionListener);
		this.bntGuardar.addActionListener(actionListener);
		this.bntEliminar.addActionListener(actionListener);
		this.bntCancelar.addActionListener(actionListener);
		this.bntSalir.addActionListener(actionListener);
	}
	
	public void mostrarMensaje(String mensaje) {
		JOptionPane.showMessageDialog(this, mensaje);
	}
	public JTextField Gettxtcodprod()
	{
	   return txtcodprod;
    }
	public void Settxtcodprod(String str)
	{
	   txtcodprod.setText(str);
    }
	public JTextField Gettxtpreciou()
	{
	   return txtpreciou;
    }
	public void Settxtpreciou(String str)
	{
		txtpreciou.setText(str);
    }
	public JTextField Gettxtdescripcion()
	{
	   return txtdescripcion;
    }
	public void Settxtdescripcion(String str)
	{
		txtdescripcion.setText(str);
    }
	public JComboBox GetcomboCategoria()
	{
	   return comboCategoria;
    }
	public void SetcomboCategoria(int i)
	{
		comboCategoria.setSelectedIndex(i);
    }
	public void SetcomboCategoria(String str)
	{
		ComboBoxModel modelo = new DefaultComboBoxModel(str.split(","));
		comboCategoria.setModel(modelo);
    }
	//
	public void EnabledBntEliminar(boolean x)
	{
		bntEliminar.setEnabled(x);
	}
	
	public void Enabledtxtcodprod(boolean x)
	{
		txtcodprod.setEnabled(x);
	}
	
	public void EnabledBntGuardar(boolean x)
	{
		bntGuardar.setEnabled(x);
	}
		
	public JTextField getTxtcantidad() {
		return txtcantidad;
	}
	
	public JTable getTablaIngredienteProd() {
		return TablaIngredienteProd;
	}
	
	public JScrollPane getTablaIngredientes() {
		return TablaIngredientes;
	}
	///////////////////////////////////////////////////////////////////////
	

}
